import api from '../index'
import type { ResponseData,PagingData, pageParam } from '../type'
import type { GoodsItem, CouponsItem } from '.'

export interface ShareCouponProductItem extends GoodsItem {
	couponId?: string
	couponName?: string
	shareUrl?: string
	couponShareCode?: string
}
// 劵码商品列表
export const getCouponShareProductList = (data: { proName?: string }) =>
	api.get<ResponseData<ShareCouponProductItem[]>>('customer/api/activity/coupon/share/proList', {
		data
	}
	)
export interface ShareCouponCodeItem {
	couponId: string
	shareUrl: string
	couponShareCode: string
}
export interface ShareCouponItem extends CouponsItem {
	categoryIds: string
	subareaIds: string,
	useTimeType:number
	useStartTime:string
	useEndTime:string
	enableDays:string
	discountMoney:string
	useStatus?:number
	list?: ShareCouponCodeItem[]
}
//获取高级分享优惠码列表
export const getCouponShareCouponList = (data: { type: string|number, proId?: string }) =>
	api.get<ResponseData<ShareCouponItem[]>>('customer/api/activity/coupon/share/list', {
		data
	}
	)

//生成分享码
export const postGenerateCode = (data: { shareUrl: string,pcShareUrl:string, couponId: string }) =>
	api.get<ResponseData<ShareCouponCodeItem[]>>('customer/api/activity/coupon/share/generateCode', {
		data
	}
	)

export interface ShareCouponDetailItem {
	couponId: string
	couponName:string
	shareUrl: string
	couponShareCode: string
	id:number
	status:number
	shareTime:string
	receiveTime:string
	receiveNickName:string
	receiveUserName:string
}
//分享明细
export const getCouponShareDetail = (data: pageParam & { status?: number, couponId?: string, couponShareCode?: string }) =>
	api.get<ResponseData<PagingData<ShareCouponDetailItem>>>('customer/api/activity/coupon/share/detail',
		{
			data
		}
	)


//通过劵码获取可用的优惠劵id
export const getCouponByShare = (data: { couponShareCode: string }) =>
	api.get<ResponseData<string>>(`customer/api/activity/coupon/share/get`, {
		data
	})
	
//通过劵码领取优惠劵
export const receiveSecurities = (code:string) =>
	api.post(`customer/api/activity/coupon/share/receiveSecurities/${code}`,{
		custom:{
			isLoading:true
		}
	})